<i>IClient</i> interface is used for working with live data and <i>ITesterClient</i> inherits its functionality for working with historical data. This article provides examples of major IClient features. The examples are based upon the Main.java example located in the <a href="http://www.dukascopy.com/client/jforexlib/JForex-SDK.zip">JForex-SDK</a> project. Thus in order to test attachment-less snippets one should simply integrate them in the Main.java example program. <br/><div class="dw_article_headers_list"><div class="dw_article_header_h1"><a href="#IClient_functionality/Connect">Connect</a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/System_listener"> System listener </a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/Subscribing_to_instruments"> Subscribing to instruments </a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/Running_strategies"> Running strategies </a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Running_remote_strategies">Running remote strategies</a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/Stopping_strategy">Stopping strategy</a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/Work_with_charts">Work with charts</a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Open_a_chart_from_IClient">Open a chart from IClient</a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Handle_IContext.openChart">Handle IContext.openChart</a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Add_chart_objects">Add chart objects</a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Change_chart_theme">Change chart theme</a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/Program_communicating_with_a_strategy">Program communicating with a strategy</a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Client_action_on_order_fill_and_close">Client action on order fill and close</a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Client_covers_up_strategy_fills">Client covers up strategy fills</a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/News_and_Calendar"> News and Calendar </a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Time_frame"> Time frame </a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Filter_parameters"> Filter parameters </a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Filter_keywords"> Filter keywords </a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/News_filter_example"> News filter example </a></div><div class="dw_article_header_h2"><a href="#IClient_functionality/Calendar_filter_example"> Calendar filter example </a></div><div class="dw_article_header_h1"><a href="#IClient_functionality/Compile_a_strategy_to_a_jfx_file">Compile a strategy to a jfx file</a></div></div><span id="IClient_functionality/Connect"><h1>Connect</h1></span>One gets an instance of <i>IClient</i> by using <i>ClientFactory.getDefaultInstance()</i>. One connects to dukascopy servers by using the <i>connect</i> method, for example:<br/><div class="dw_article_geshi_code">client.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://www.dukascopy.com/client/demo/jclient/jforex.jnlp&quot;</span>, <span style="color: #0000ff;">&quot;username&quot;</span>, <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>For connecting to LIVE servers see <a href="#JForex_SDK_LIVE_mode">here</a>.<br/><span id="IClient_functionality/System_listener"><h1> System listener </h1></span><a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/system/ISystemListener.html"><i>ISystemListener</i></a> interface allows the user to execute some business logic on system connects and disconnects as well as on start and stop of every strategy. System listener gets added to <i>IClient</i> by using the <i>setSystemListener</i> method, for instance:<br/><div class="dw_article_geshi_code">client.<span style="color: #006633;">setSystemListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ISystemListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> lightReconnects <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStart<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> processId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Strategy started: &quot;</span> <span style="color: #339933;">+</span> processId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStop<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> processId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Strategy stopped: &quot;</span> <span style="color: #339933;">+</span> processId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>client.<span style="color: #006633;">getStartedStrategies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onConnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; lightReconnects <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onDisconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Disconnected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lightReconnects <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TRY TO RECONNECT, reconnects left: &quot;</span> <span style="color: #339933;">+</span> lightReconnects<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #006633;">reconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">--</span>lightReconnects<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//sleep for 10 seconds before attempting to reconnect</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//ignore</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span>jnlpUrl, userName, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div><span id="IClient_functionality/Subscribing_to_instruments"><h1> Subscribing to instruments </h1></span>In contrary to JForex client, in Standalone API one always has to explicitly subscribe to all instruments that his strategy is going to use. This can be done by using the <i>setSubscribedInstruments</i> method. Note that the subscription is asynchronous, thus if the in it is advised to subscribe in the following way:<br/><div class="dw_article_geshi_code">Set<span style="color: #339933;">&lt;</span>Instrument<span style="color: #339933;">&gt;</span> instruments <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashSet<span style="color: #339933;">&lt;</span>Instrument<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />instruments.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span>.<span style="color: #006633;">EURSEK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />instruments.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span>.<span style="color: #006633;">AUDUSD</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />client.<span style="color: #006633;">setSubscribedInstruments</span><span style="color: #009900;">&#40;</span>instruments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">// wait max 2 seconds for the instruments to get subscribed</span><br /><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>client.<span style="color: #006633;">getSubscribedInstruments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">containsAll</span><span style="color: #009900;">&#40;</span>instruments<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Instruments not subscribed yet &quot;</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; i<span style="color: #339933;">--;</span><br /><span style="color: #009900;">&#125;</span></div><span id="IClient_functionality/Running_strategies"><h1> Running strategies </h1></span>One runs a strategy by passing it to <i>IClient.startStrategy</i>, for instance:<br/><div class="dw_article_geshi_code">client.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MA_Play<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>One might also run multiple strategies. For instance, one might run two instances of the same strategy but with different parameters:<br/><div class="dw_article_geshi_code">StrategySimple strategy1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StrategySimple<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />StrategySimple strategy2 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StrategySimple<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />strategy1.<span style="color: #006633;">amount</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.01</span><span style="color: #339933;">;</span><br />strategy1.<span style="color: #006633;">stopLossPips</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />strategy1.<span style="color: #006633;">takeProfitPips</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br />strategy2.<span style="color: #006633;">amount</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.02</span><span style="color: #339933;">;</span><br />strategy2.<span style="color: #006633;">stopLossPips</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span><br />strategy2.<span style="color: #006633;">takeProfitPips</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />client.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span>strategy1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />client.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span>strategy2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div><span id="IClient_functionality/Running_remote_strategies"><h2>Running remote strategies</h2></span>One can run a remote strategy by calling the <i>IClient.getRemoteStrategyManager().startStrategy</i> method. For other remote strategy management methods see <a href="http://www.dukascopy.com/client/javadoc/com/dukascopy/api/strategy/IStrategyManager.html">IStrategyManager</a><br/>Consider an example program which is runs and manages remote strategies:<br/><div class="dw_article_geshi_code"><span style="color: #003399;">File</span> jfxFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;src/singlejartest/MA_Play.jfx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>jfxFile.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>jfxFile <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; does not exist! Please compile the strategy or choose another path.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #009900;">&#125;</span><br /><br /><span style="color: #000000; font-weight: bold;">final</span> IRemoteStrategyManager remoteManager <span style="color: #339933;">=</span> client.<span style="color: #006633;">getRemoteStrategyManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />remoteManager.<span style="color: #006633;">addStrategyListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RemoteStrategyListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStrategyRun<span style="color: #009900;">&#40;</span>IRemoteStrategyDescriptor descriptor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;remote startegy launched: &quot;</span> <span style="color: #339933;">+</span> descriptor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>descriptor.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>myStrategyId<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Not our designated remote strategy - stop it!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; remoteManager.<span style="color: #006633;">stopStrategy</span><span style="color: #009900;">&#40;</span>descriptor.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStrategyStop<span style="color: #009900;">&#40;</span>IRemoteStrategyDescriptor descriptor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;remote startegy stopped: &quot;</span> <span style="color: #339933;">+</span> descriptor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br /><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">// start a strategy without fetching the id</span><br />remoteManager.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span>jfxFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">// start and fetch the id</span><br />IStrategyResponse<span style="color: #339933;">&lt;</span>UUID<span style="color: #339933;">&gt;</span> startResponse <span style="color: #339933;">=</span> remoteManager.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span>jfxFile<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>startResponse.<span style="color: #006633;">isError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; LOGGER.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Remote strategy failed to start: &quot;</span> <span style="color: #339933;">+</span> startResponse.<span style="color: #006633;">getErrorMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; myStrategyId <span style="color: #339933;">=</span> startResponse.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Remote strategy successfully started: &quot;</span> <span style="color: #339933;">+</span> myStrategyId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #009900;">&#125;</span><br /><br />Set<span style="color: #339933;">&lt;</span>IRemoteStrategyDescriptor<span style="color: #339933;">&gt;</span> strategyDescriptors <span style="color: #339933;">=</span> remoteManager.<span style="color: #006633;">getStartedStrategies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Remotely started &quot;</span> <span style="color: #339933;">+</span> strategyDescriptors.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; strategies: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>IStrategyDescriptor strategyDescriptor <span style="color: #339933;">:</span> strategyDescriptors<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>strategyDescriptor.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/https://www.dukascopy.com/wiki/files/MainRemote.java">MainRemote.java</a><br/><b>Note:</b> The functionality is available with JForex-API 2.9.5.<br/><span id="IClient_functionality/Stopping_strategy"><h1>Stopping strategy</h1></span>One retrieves strategy process id from <i>IClient.startStrategy</i>, which afterwards can be used to stop the strategy by using the <i>IClient.stopStrategy</i> method. Consider a program which starts an anonymous strategy and checks every second if the user has typed in the console "stop", if so then the program stops the strategy.<br/><div class="dw_article_geshi_code"><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> strategyId <span style="color: #339933;">=</span> client.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IStrategy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Instrument</span> instrument <span style="color: #339933;">=</span> <span style="color: #003399;">Instrument</span>.<span style="color: #006633;">EURUSD</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IConsole console<span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStart<span style="color: #009900;">&#40;</span>IContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; console <span style="color: #339933;">=</span> context.<span style="color: #006633;">getConsole</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onBar<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, Period period, IBar askBar, IBar bidBar<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> instrument <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">instrument</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #006633;">getOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; bar: &quot;</span> <span style="color: #339933;">+</span> period &nbsp;<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> askBar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTick<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, ITick tick<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onMessage<span style="color: #009900;">&#40;</span>IMessage message<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onAccount<span style="color: #009900;">&#40;</span>IAccount account<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #666666; font-style: italic;">//now it's running</span><br /><br /><span style="color: #666666; font-style: italic;">//every second check if &quot;stop&quot; had been typed in the console - if so - then stop the strategy</span><br /><span style="color: #003399;">Thread</span> thread <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; Scanner s <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Scanner<span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">in</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> str <span style="color: #339933;">=</span> s.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>str.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;stop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Strategy stop by console command.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #006633;">stopStrategy</span><span style="color: #009900;">&#40;</span>strategyId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />thread.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div><a href="https://www.dukascopy.com/wiki/files//MainStopFromConsole.java">MainStopFromConsole.java</a><br/><span id="IClient_functionality/Work_with_charts"><h1>Work with charts</h1></span>There are two ways how one can open a chart:<br/><ol><li><i>IClient.openChart</i> is used to open a chart without running a strategy.</li><li><i>IClient.addClientGUIListener</i> adds a listener for the program to handle <i>IContext.openChart</i> and <i>IContext.closeChart</i> events.</li></ol><span id="IClient_functionality/Open_a_chart_from_IClient"><h2>Open a chart from <i>IClient</i></h2></span><b>Note:</b> Available with JForex-API 2.7.1<br/>Consider opening multiple charts - for each instrument in an array <i>instrArr</i>:<br/><div class="dw_article_geshi_code"><span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument <span style="color: #339933;">:</span> instrArr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; IFeedDescriptor feedDescriptor <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TicksFeedDescriptor<span style="color: #009900;">&#40;</span>instrument<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; feedDescriptor.<span style="color: #006633;">setOfferSide</span><span style="color: #009900;">&#40;</span>OfferSide.<span style="color: #006633;">BID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// need to set due to platform requirements</span><br />&nbsp; &nbsp; IChart chart <span style="color: #339933;">=</span> client.<span style="color: #006633;">openChart</span><span style="color: #009900;">&#40;</span>feedDescriptor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">final</span> IClientGUI clientGUI <span style="color: #339933;">=</span> client.<span style="color: #006633;">getClientGUI</span><span style="color: #009900;">&#40;</span>chart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #003399;">SwingUtilities</span>.<span style="color: #006633;">invokeLater</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ChartFrame frame <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ChartFrame<span style="color: #009900;">&#40;</span>clientGUI, client.<span style="color: #006633;">getSubscribedInstruments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chartFrameMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>clientGUI.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, frame<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Handle manual close - we need to call IClient.closeChart for strategy to know that the chart is no more there</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frame.<span style="color: #006633;">addWindowListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">WindowAdapter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowClosing<span style="color: #009900;">&#40;</span><span style="color: #003399;">WindowEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Chart manually closed, removing the chart from the strategy context&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #006633;">closeChart</span><span style="color: #009900;">&#40;</span>clientGUI.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chartFrameMap.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>clientGUI.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>chartFrameMap.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;All charts closed, stopping the program&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/files//MainOpenChart.java">MainOpenChart.java</a><br/><span id="IClient_functionality/Handle_IContext.openChart"><h2>Handle <i>IContext.openChart</i></h2></span>Consider a program which opens a chart whenever the strategy calls <i>IContext.openChart</i> and closes a chart whenever the strategy call <i>IContext.closeChart</i>:<br/><div class="dw_article_geshi_code">client.<span style="color: #006633;">addClientGUIListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> IClientGUIListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp;<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onOpenChart<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> IClientGUI clientGUI<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Chart opened from a startegy &quot;</span> <span style="color: #339933;">+</span> clientGUI.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFeedDescriptor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">SwingUtilities</span>.<span style="color: #006633;">invokeLater</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ChartFrame frame <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ChartFrame<span style="color: #009900;">&#40;</span>clientGUI, client.<span style="color: #006633;">getSubscribedInstruments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chartFrameMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>clientGUI.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, frame<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Handle manual close - we need to call IClient.closeChart for strategy to know that the chart is no more there</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frame.<span style="color: #006633;">addWindowListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">WindowAdapter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowClosing<span style="color: #009900;">&#40;</span><span style="color: #003399;">WindowEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Chart manually closed, removing the chart from the strategy context&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.<span style="color: #006633;">closeChart</span><span style="color: #009900;">&#40;</span>clientGUI.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; updateOnClose<span style="color: #009900;">&#40;</span>clientGUI.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCloseChart<span style="color: #009900;">&#40;</span>IChart chart<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Chart closed from a startegy &quot;</span> <span style="color: #339933;">+</span> chart.<span style="color: #006633;">getFeedDescriptor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//we need to take care of closing the frame ourselves in gui</span><br />&nbsp; &nbsp; &nbsp; &nbsp; ChartFrame frame <span style="color: #339933;">=</span> chartFrameMap.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>chart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; frame.<span style="color: #006633;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; updateOnClose<span style="color: #009900;">&#40;</span>chart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> updateOnClose<span style="color: #009900;">&#40;</span>IChart chart<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; chartFrameMap.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>chart<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>chartFrameMap.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;All charts closed, stopping the program&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div><a href="https://www.dukascopy.com/wiki/files//MainHandleStrategyOpenChart.java">MainHandleStrategyOpenChart.java</a><br/><span id="IClient_functionality/Add_chart_objects"><h2>Add chart objects</h2></span>One can not only plot chart objects <a href="#Create_and_manage_chart_objects">from within a strategy</a>, but also from the program running <i>IClient</i>. Consider creating a button panel which receives an <i>IChart</i> from <i>IClientGUI.getChart()</i>:<br/><div class="dw_article_geshi_code">@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serial&quot;</span><span style="color: #009900;">&#41;</span><br /><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> ChartObjectPanel <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">JPanel</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> IChart chart<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ChartObjectPanel<span style="color: #009900;">&#40;</span>IChart chart<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">chart</span> <span style="color: #339933;">=</span> chart<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; addButtons<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> addButtons<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">JButton</span> btnVLine <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">JButton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Add VLine&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; btnVLine.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actionPerformed<span style="color: #009900;">&#40;</span><span style="color: #003399;">ActionEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//draw the line at the time of the last drawn feed element on the chart</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ITimedData<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> chartData <span style="color: #339933;">=</span> chart.<span style="color: #006633;">getLastRequestedData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> time <span style="color: #339933;">=</span> chartData<span style="color: #009900;">&#91;</span>chartData.<span style="color: #006633;">length</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IChartObject obj <span style="color: #339933;">=</span> chart.<span style="color: #006633;">getChartObjectFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createVerticalLine</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;vLine&quot;</span>, time<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; add<span style="color: #009900;">&#40;</span>btnVLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">JButton</span> btnHLine <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">JButton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Add HLine&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; btnHLine.<span style="color: #006633;">addActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ActionListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> actionPerformed<span style="color: #009900;">&#40;</span><span style="color: #003399;">ActionEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//draw the line in the chart price axis midpoint</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> price <span style="color: #339933;">=</span> chart.<span style="color: #006633;">getMinPrice</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>chart.<span style="color: #006633;">getMaxPrice</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> chart.<span style="color: #006633;">getMinPrice</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%.5f&quot;</span>, price<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IChartObject obj <span style="color: #339933;">=</span> chart.<span style="color: #006633;">getChartObjectFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createHorizontalLine</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hLine&quot;</span>, price<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Color</span>.<span style="color: #006633;">GREEN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; add<span style="color: #009900;">&#40;</span>btnHLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/files//MainOpenChartAddChartObject.java">MainOpenChartAddChartObject.java</a><br/><span id="IClient_functionality/Change_chart_theme"><h2>Change chart theme</h2></span><b>Note:</b> Available with JForex-API 2.7.9<br/><i>IChartTheme</i> represents a chart theme, it can be retreived and set to a chart by using the <i>getTheme</i> and <i>setTheme</i> methods of the <i>IClientChartPresentationManager</i> interface. Consider changing chart's background and tick/candle colors:<br/><div class="dw_article_geshi_code">chartPresentationManager.<span style="color: #006633;">setTheme</span><span style="color: #009900;">&#40;</span><br />&nbsp; &nbsp; chartPresentationManager.<span style="color: #006633;">getTheme</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">setName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Custom tick/candle color theme&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>ColoredElement.<span style="color: #006633;">BACKGROUND</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">254</span>, <span style="color: #cc66cc;">244</span>, <span style="color: #cc66cc;">214</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>ColoredElement.<span style="color: #006633;">CANDLE_BEAR</span>, <span style="color: #003399;">Color</span>.<span style="color: #006633;">CYAN</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>ColoredElement.<span style="color: #006633;">CANDLE_BULL</span>, <span style="color: #003399;">Color</span>.<span style="color: #006633;">ORANGE</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>ColoredElement.<span style="color: #006633;">ASK</span>, <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span>.<span style="color: #006633;">darker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; .<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>ColoredElement.<span style="color: #006633;">BID</span>, <span style="color: #003399;">Color</span>.<span style="color: #006633;">PINK</span>.<span style="color: #006633;">darker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br /><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>One can retrieve a predefined theme by calling the <i>IClientChartPresentationManager.getPredefinedTheme</i> method. Consider setting a predefined theme to a chart:<br/><div class="dw_article_geshi_code">chartPresentationManager.<span style="color: #006633;">setTheme</span><span style="color: #009900;">&#40;</span>chartPresentationManager.<span style="color: #006633;">getPredefinedTheme</span><span style="color: #009900;">&#40;</span>IChartTheme.<span style="color: #006633;">Predefined</span>.<span style="color: #006633;">BLUE_BLACK_ON_GRAY</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>For full usage example look up the <i>cmbChartTheme</i> combo box in:<br/><a href="https://www.dukascopy.com/wiki/files//MainOpenChart.java">MainOpenChart.java</a><br/><span id="IClient_functionality/Program_communicating_with_a_strategy"><h1>Program communicating with a strategy</h1></span>By defining a listener (in the means of public interface) within a strategy one can implement some client side logic on strategy events.<br/><span id="IClient_functionality/Client_action_on_order_fill_and_close"><h2>Client action on order fill and close</h2></span>Consider that from the program you wish to do some extra logging on both order fill and close. And also you wish to set order stop loss:<br/><div class="dw_article_geshi_code">client.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> StrategyPublicMethods<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> StrategyPublicMethods.<span style="color: #006633;">ClientActions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onOrderFill<span style="color: #009900;">&#40;</span>IOrder order<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Order filled, execute here some logic on client side, say set stop loss if the order is long&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>order.<span style="color: #006633;">isLong</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order.<span style="color: #006633;">setStopLossPrice</span><span style="color: #009900;">&#40;</span>order.<span style="color: #006633;">getOpenPrice</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> order.<span style="color: #006633;">getInstrument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getPipValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JFException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onOrderClose<span style="color: #009900;">&#40;</span>IOrder order<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Order closed, execute here some logic on client side&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>Consider introducing an interface in a strategy which would serve as an order fill and close listener. Implementation of the interface would get passed from the <i>IClient </i>program:<br/><div class="dw_article_geshi_code"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StrategyPublicMethods <span style="color: #000000; font-weight: bold;">implements</span> IStrategy <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IConsole console<span style="color: #339933;">;</span> <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IEngine engine<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> StrategyPublicMethods.<span style="color: #006633;">ClientActions</span> clientActions<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ClientActions <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> onOrderClose<span style="color: #009900;">&#40;</span>IOrder order<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> onOrderFill<span style="color: #009900;">&#40;</span>IOrder order<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp;<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//for the launch from standalone</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> StrategyPublicMethods <span style="color: #009900;">&#40;</span>StrategyPublicMethods.<span style="color: #006633;">ClientActions</span> clientActions<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clientActions</span> <span style="color: #339933;">=</span> clientActions<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//...</span><br /><span style="color: #009900;">&#125;</span></div>Then on every order fill and close execute the logic that has been passed from the <i>IClient</i> program:<br/><div class="dw_article_geshi_code">@Override<br /><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onMessage<span style="color: #009900;">&#40;</span>IMessage message<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>message.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> IMessage.<span style="color: #006633;">Type</span>.<span style="color: #006633;">ORDER_FILL_OK</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; clientActions.<span style="color: #006633;">onOrderFill</span><span style="color: #009900;">&#40;</span>message.<span style="color: #006633;">getOrder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>message.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> IMessage.<span style="color: #006633;">Type</span>.<span style="color: #006633;">ORDER_CLOSE_OK</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; clientActions.<span style="color: #006633;">onOrderClose</span><span style="color: #009900;">&#40;</span>message.<span style="color: #006633;">getOrder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/files//StrategyPublicMethods.java">StrategyPublicMethods.java</a><br/><a href="https://www.dukascopy.com/wiki/files//MainPublicMethods.java">MainPublicMethods.java</a><br/><span id="IClient_functionality/Client_covers_up_strategy_fills"><h2>Client covers up strategy fills</h2></span>Consider another example of the same pattern - a client program that covers-up each order created by the staregy:<br/><div class="dw_article_geshi_code">client.<span style="color: #006633;">startStrategy</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> StrategyWithFillListener<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> StrategyWithFillListener.<span style="color: #006633;">ClientActions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onOrderFill<span style="color: #009900;">&#40;</span>IOrder order, IEngine engine<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Order filled, open cover-up order from client side.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//we can't open next order sooner than 1 sec after the previous one for the same instrument</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//opposite direction order with the same amount</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OrderCommand cmd <span style="color: #339933;">=</span> order.<span style="color: #006633;">isLong</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> OrderCommand.<span style="color: #006633;">SELL</span> <span style="color: #339933;">:</span> OrderCommand.<span style="color: #006633;">BUY</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; engine.<span style="color: #006633;">submitOrder</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;orderClient&quot;</span> <span style="color: #339933;">+</span> <span style="color: #339933;">++</span>counter, order.<span style="color: #006633;">getInstrument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, cmd, order.<span style="color: #006633;">getAmount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>In this case the listener intrerface only includes one method:<br/><div class="dw_article_geshi_code"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StrategyWithFillListener <span style="color: #000000; font-weight: bold;">implements</span> IStrategy <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//...</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ClientActions <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> onOrderFill<span style="color: #009900;">&#40;</span>IOrder order, IEngine engine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp;<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//for the launch from standalone</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> StrategyWithFillListener <span style="color: #009900;">&#40;</span>StrategyWithFillListener.<span style="color: #006633;">ClientActions</span> clientActions<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clientActions</span> <span style="color: #339933;">=</span> clientActions<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//...</span><br /><span style="color: #009900;">&#125;</span></div>Then on every order fill execute the logic that has been passed from the <i>IClient</i> program:<br/><div class="dw_article_geshi_code">@Override<br /><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onMessage<span style="color: #009900;">&#40;</span>IMessage message<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>message.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> IMessage.<span style="color: #006633;">Type</span>.<span style="color: #006633;">ORDER_FILL_OK</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; clientActions.<span style="color: #006633;">onOrderFill</span><span style="color: #009900;">&#40;</span>message.<span style="color: #006633;">getOrder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, engine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/files//StrategyFillListener.java">StrategyFillListener.java</a><br/><a href="https://www.dukascopy.com/wiki/files//ProgramFillCover.java">ProgramFillCover.java</a><br/><span id="IClient_functionality/News_and_Calendar"><h1> News and Calendar </h1></span>In order to receive news and/or calendar messages in a strategy, one has to apply <a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/NewsFilter.html"><i>NewsFilter</i></a> and/or <a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/CalendarFilter.html"><i>CalendarFilter</i></a> to <i>IClient</i> before the run of strategy in the following way:<br/><div class="dw_article_geshi_code">NewsFilter newsFilter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NewsFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #666666; font-style: italic;">//all today's news</span><br />newsFilter.<span style="color: #006633;">setTimeFrame</span><span style="color: #009900;">&#40;</span>NewsFilter.<span style="color: #006633;">TimeFrame</span>.<span style="color: #006633;">TODAY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />client.<span style="color: #006633;">addNewsFilter</span><span style="color: #009900;">&#40;</span>newsFilter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div><b>Note:</b> <i>NewsFilter</i> only works with live-data, meaning that you can't use it while back-testing - no news messages in strategy will arrive.<br/><br/><span id="IClient_functionality/Time_frame"><h2> Time frame </h2></span>Available time frames are defined by <a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/NewsFilter.TimeFrame.html"><i>TimeFrame</i></a> enum. One can retrieve news for the following time frames:<br/><ul><li><i>Online</i> - strategy will receive news as they arrive.</li><li><i>Last 10 minutes</i> - strategy right after its start will receive news for the last 10 minutes, from then on it news filter will behave as <i>Online</i>.</li><li><i>Last 30 minutes</i>, <i>Last hour</i>, <i>Today</i> - function the same way as <i>Last 10 minutes</i> just over a different period of time.</li><li><i>Specific date</i> - strategy right after its start will receive news for the specific date, from then on it news filter will behave as <i>Online</i>. To enable this one needs to call <i>NewsFilter.setFrom</i> with the particular date.</li></ul><span id="IClient_functionality/Filter_parameters"><h2> Filter parameters </h2></span>One may filter news by the following parameters:<br/><ul><li><a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/INewsFilter.Country.html">Countries and Regions</a>,</li><li><a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/INewsFilter.Currency.html">Currencies</a>,</li><li><a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/INewsFilter.EventCategory.html">Event Categories</a>,</li><li><a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/INewsFilter.MarketSector.html">Market Sectors</a>,</li><li><a href="http://www.dukascopy.com/client/javadoc//com/dukascopy/api/INewsFilter.StockIndex.html">Stock Indicies</a>.</li></ul>Parameter sets act like OR conditions, meaning that:<br/><ul><li>Application of no parameters will result of receiving all news messages.</li><li>Application of one parameter <i>StockIndex.NYSE</i> will result in strategy receiving ONLY news that are related to NYSE stock index.</li><li>Application of multiple parameters <i>Country.FR</i> and <i>StockIndex.NYSE</i> will result in strategy receiving ONLY news that are related to NYSE stock index or that are related to France.</li></ul><span id="IClient_functionality/Filter_keywords"><h2> Filter keywords </h2></span>Keyword filtering can be perceived as an extra filter on top of parameter filtering, since it drops from parameter filtering results the ones that don't match the given text string criteria.<br/><br/><span id="IClient_functionality/News_filter_example"><h2> News filter example </h2></span>Consider filtering all today's news related to NYSE stock index or DJI stock index or USA or France. On top of that, take only news that contain words "Profit" and "Loss":<br/><div class="dw_article_geshi_code">NewsFilter newsFilter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NewsFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />newsFilter.<span style="color: #006633;">setTimeFrame</span><span style="color: #009900;">&#40;</span>NewsFilter.<span style="color: #006633;">TimeFrame</span>.<span style="color: #006633;">TODAY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">//filter indicies</span><br />newsFilter.<span style="color: #006633;">getStockIndicies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>INewsFilter.<span style="color: #006633;">StockIndex</span>.<span style="color: #006633;">NYSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />newsFilter.<span style="color: #006633;">getStockIndicies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>INewsFilter.<span style="color: #006633;">StockIndex</span>.<span style="color: #006633;">DJI</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">//filter countries and regions</span><br />newsFilter.<span style="color: #006633;">getCountries</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>INewsFilter.<span style="color: #006633;">Country</span>.<span style="color: #006633;">US</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />newsFilter.<span style="color: #006633;">getCountries</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>INewsFilter.<span style="color: #006633;">Country</span>.<span style="color: #006633;">FR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><br /><span style="color: #666666; font-style: italic;">//filter keywords</span><br />newsFilter.<span style="color: #006633;">getKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Profit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />newsFilter.<span style="color: #006633;">getKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Loss&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />client.<span style="color: #006633;">addNewsFilter</span><span style="color: #009900;">&#40;</span>newsFilter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div><a href="https://www.dukascopy.com/wiki/files//NewsFilterMain.java">NewsFilterMain.java</a><br/><a href="https://www.dukascopy.com/wiki/files//NewsStrategyNoTrades.java">NewsStrategyNoTrades.java</a><br/><span id="IClient_functionality/Calendar_filter_example"><h2> Calendar filter example </h2></span>Consider filtering calendar events over 11th March of 2011 that are related to G7 countries. On top of that, take only events that contain one of the three keywords: "Treasury", "GDP", "trade":<br/><div class="dw_article_geshi_code">CalendarFilter calendarFilter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CalendarFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />calendarFilter.<span style="color: #006633;">setTimeFrame</span><span style="color: #009900;">&#40;</span>NewsFilter.<span style="color: #006633;">TimeFrame</span>.<span style="color: #006633;">SPECIFIC_DATE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">// custom historical interval</span><br /><span style="color: #003399;">SimpleDateFormat</span> dateFormat <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yyyy-MM-dd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />dateFormat.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #003399;">Date</span> dateFrom <span style="color: #339933;">=</span> dateFormat.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;2011-03-11&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />calendarFilter.<span style="color: #006633;">setFrom</span><span style="color: #009900;">&#40;</span>dateFrom<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; <br /><br /><span style="color: #666666; font-style: italic;">//filter countries and regions</span><br />newsFilter.<span style="color: #006633;">getCountries</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>INewsFilter.<span style="color: #006633;">Country</span>.<span style="color: #006633;">G7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">//filter keywords</span><br />calendarFilter.<span style="color: #006633;">getKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Treasury&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />calendarFilter.<span style="color: #006633;">getKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GDP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />calendarFilter.<span style="color: #006633;">getKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;trade&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />client.<span style="color: #006633;">addNewsFilter</span><span style="color: #009900;">&#40;</span>calendarFilter<span style="color: #009900;">&#41;</span></div><a href="https://www.dukascopy.com/wiki/files//NewsFilterMain.java">NewsFilterMain.java</a><br/><a href="https://www.dukascopy.com/wiki/files//NewsStrategyNoTrades.java">NewsStrategyNoTrades.java</a><br/><span id="IClient_functionality/Compile_a_strategy_to_a_jfx_file"><h1>Compile a strategy to a jfx file</h1></span>By using the <i>IClient.compileStrategy</i> method, one can compile a strategy from his standalone program. For instance:<br/><div class="dw_article_geshi_code">&nbsp; client.<span style="color: #006633;">compileStrategy</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:/temp/MyStrategy.java&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div>